10. CODE: Complete A* Search
Complete A* Search
In this exercise, you will complete AStarSearch()
in route_planner.cpp
using the NextNode
, ConstructFinalPath
, and AddNeighbors
methods you have written previously.
## To complete this exercise:
- Delete the current contents of
AStarSearch
. - Use the
NextNode
,ConstructFinalPath
andAddNeighbors
methods to implement the pseudocode below inAStarSearch
:
## Pseudocode
AStarSearch:
Set
start_node->visited
to betrue
.Push
start_node
to the back ofopen_list
.Create a pointer
RouteModel::Node *current_node
and initialize the pointer tonullptr
.while the
open_list
size is greater than 0:- Set the
current_node
pointer to the results of callingNextNode
. - if the distance from
current_node
to theend_node
is 0:
- Call
ConstructFinalPath
usingcurrent_node
and setm_Model.path
with the results. - Return to exit the A* search.
- else call
AddNeighbors
with thecurrent_node
.
- Set the
Workspace
This section contains either a workspace (it can be a Jupyter Notebook workspace or an online code editor work space, etc.) and it cannot be automatically downloaded to be generated here. Please access the classroom with your account and manually download the workspace to your local machine. Note that for some courses, Udacity upload the workspace files onto https://github.com/udacity, so you may be able to download them there.
Workspace Information:
- Default file path:
- Workspace type: react
- Opened files (when workspace is loaded): n/a
-
userCode:
export CXX=g++-7
export CXXFLAGS=-std=c++17
cmake_tests() {
/usr/local/bin/cmake -DTESTING="AStarSearch" "$1"
}
export -f cmake_tests
Solution
Final A Star